/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.mx.saco.util;

import java.text.NumberFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 *
 * @author LY005213
 */
public class Util {

    public static String USER_SESSION_KEY = "user_20142611";
    public static boolean VIGENTE = Boolean.TRUE;
    public static Long ESTATUS_USUARIO_ELIMINADO = 25L;
    public static Long CATALOGO_USUARIO_ESTATUS = 1L;
    public static Long CATALOGO_CLIENTE_TIPO = 2L;
    public static Long CATALOGO_METODO_PAGO = 4L;
    public static Long CATALOGO_TIPO_MONEDA = 5L;
    public static Long CATALOGO_TIPO_COMPROBANTE = 6L;
    public static Long CATALOGO_PORC_IVA = 9L;
    public static Long TIPO_PERSONA_MORAL=4L;
    public static Long TIPO_PERSONA_FISICA=3L;

    public static final String PATTERN_EMAIL = "^[_A-Za-z0-9-\\+]+(\\.[_A-Za-z0-9-]+)*@[A-Za-z0-9-]+(\\.[A-Za-z0-9]+)*(\\.[A-Za-z]{2,})$";

    public static final Calendar convertirFecha(String format, Date fecha) throws ParseException {

        Date date = new Date();
        SimpleDateFormat fomateador = new SimpleDateFormat(format);
        String s = fomateador.format(date);

        Calendar cal;
        cal = Calendar.getInstance();
        cal.setTime(fomateador.parse(s));
        //System.out.println(cal.getTime());
        return cal;

    }

    public static String getDate(Date fecha, String formato) {

        SimpleDateFormat fomateador = new SimpleDateFormat(formato);
        return fomateador.format(fecha);
    }

    public static boolean validateEmail(String email) {

        // Compiles the given regular expression into a pattern.
        Pattern pattern = Pattern.compile(PATTERN_EMAIL);

        // Match the given input against this pattern
        Matcher matcher = pattern.matcher(email);
        return matcher.matches();

    }

    public static double formatDouble(int fracDigit, double val) {
        NumberFormat nf = NumberFormat.getInstance();
//Establecemos el numero de decimales 
        nf.setMaximumFractionDigits(fracDigit);
//Convertimos el numero 
        String st = nf.format(val);
//lo vuelves a convertir a double 
        st=st.replace(",", "");
        double dou = Double.valueOf(st);
        return dou;
    }

}
